package com.bingqing.service;

import com.bingqing.dao.HotelDao;
import com.bingqing.dao.TypeDao;
import com.bingqing.entity.Hotel;
import com.bingqing.entity.Params;
import com.bingqing.entity.Type;
import com.bingqing.exception.CustomException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: TypeService
 * Package: com.bingqing.service
 * Description:
 *
 * @Author liuyujie
 * @Create 2024-03-10 9:23
 * @Version 1.0
 */
@Service
public class HotelService {
    @Resource
    HotelDao hotelDao;


    //分页查询
    public PageInfo<Hotel> findBySearch(Params params) {
        PageHelper.startPage(params.getPageNum(),params.getPageSize());
        List<Hotel> list=  hotelDao.findBySearch(params);
        return PageInfo.of(list);
    }



    public void add(Hotel hotel) {
        //1.判断是否为空
        if(hotel.getName() == null || "".equals(hotel.getName())){
            throw new CustomException("请输入名字");
        }
        //2.判断是否重复
        Hotel dbHotel= hotelDao.selectByName(hotel.getName());
        if(dbHotel!=null){
            throw new CustomException("该酒店已存在，请重新输入");
        }
        //3.插入数据
        hotelDao.insertSelective(hotel);
    }

    public void update(Hotel hotel) {
        //1.判断是否为空
        if(hotel.getName() == null || "".equals(hotel.getName())){
            throw new CustomException("请输入名字");
        }
        hotelDao.updateByPrimaryKeySelective(hotel);
    }

    public void deleteById(Integer id) {
        hotelDao.deleteByPrimaryKey(id);
    }


}
